
import Aedes from 'aedes'
import http from 'http'
import { createServer } from 'net'
import ws from 'websocket-stream'

import { port, wsPort } from './config.js'

// const aedes = require('aedes')()
// const httpServer = require('http').createServer()
// const ws = require('websocket-stream')
// const port = 8888
const aedes = new Aedes({ port })
const server = createServer(aedes.handle)
const httpServer = http.createServer()
ws.createServer({ server: httpServer }, aedes.handle)


server.listen(port, function () {
  console.log('\n\nAdes MQTT listening on port: ' + port)
})

httpServer.listen(wsPort, function () {
  console.log('Aedes MQTT-WS listening on port: ' + wsPort)
  // aedes.publish({ topic: 'aedes/hello', payload: "I'm broker " + aedes.id })
})
